package DataStructure.TreeLearning.BinarySortTree;

import java.util.ArrayList;
import java.util.List;

/**
 *  测试类
 */
public class TestDemo {
    public static void main(String[] args) {
        MyBinarySortTreeImpl<Integer> tree =  new MyBinarySortTreeImpl<>();
        // 前序：[5, 2, 0, -4, -1, 3, 19, 12, 38]
        int[] preArr = {5, 2, 0, -4, -1, 3, 19, 12, 38};
        // 中序：[-4, -1, 0, 2, 3, 5, 12, 19, 38]
        int[] inArr = {-4, -1, 0, 2, 3, 5, 12, 19, 38};
        // 后序：[-1, -4, 0, 3, 2, 12, 38, 19, 5]
        int[] postArr = {-1, -4, 0, 3, 2, 12, 38, 19, 5};

        List<Integer> preList = new ArrayList<>();
        List<Integer> inList = new ArrayList<>();
        List<Integer> postList = new ArrayList<>();
        // 将前序、中序、后序存入List集合中
        for(int i=0; i<preArr.length; i++) {
            preList.add(preArr[i]);
        }
        for(int i=0; i<inArr.length; i++) {
            inList.add(inArr[i]);
        }
        for(int i=0; i<postArr.length; i++) {
            postList.add(postArr[i]);
        }

        // 根据前序和中序建树
        tree.buildTreeByPreAndIn(preList, inList);
        // 根据中序和后序建树
        //tree.buildTreeByInAndPost(inList, postList);

        // 验证：
        System.out.println("PreOrder:");
        System.out.println(tree.preOrder_Stack());
        System.out.println("----------------------------");

        // 递归删除节点
        tree.remove_Recursion(38);

        System.out.println("-----------------------------");
        System.out.println("PreOrder:");
        System.out.println(tree.preOrder_Stack());
    }
}
